package com.ydkfjs.controller;

import com.ydkfjs.common.Result;
import com.ydkfjs.utils.FileUtils;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;

/**
 * @Author: hb
 * @CreateTime: 2024-04-07 08:29
 * @Version: 1.0
 */
@Api(tags = "文件模块")
@RestController
@RequestMapping("/file")
@Slf4j
public class FileController {

    private final FileUtils fileUtils;

    public FileController(FileUtils fileUtils) {
        this.fileUtils = fileUtils;
    }

    /**
     * 文件上传
     * @param file
     * @return
     */
    @PostMapping("/upload")
    public Result<?> upload(@RequestParam MultipartFile file){
        return fileUtils.upload(file);
    }

    /**
     * 文件下载
     * @param name
     * @param response
     */
    @GetMapping("/download")
    public void download(@RequestParam String name, HttpServletResponse response){
        fileUtils.download(name,response);
    }
}
